import service from '@/utils/axios';
import {
    ChatConfig,
    ChatGptRO,
    GetCodeRO,
    GptSessionVO,
    MessageContentDto,
    ParseCodeRO,
    ProductVO
} from '@/api/chatgpt/chatgpt';
import { IResponseType } from '@/api/common';

export const sendMessages = (data: ChatGptRO) => {
    return service<IResponseType<void>>({
        url: '/chat/saveMessages',
        method: 'post',
        data
    });
};

export const saveContent = (sessionId: string, data: ChatGptRO) => {
    return service<IResponseType<void>>({
        url: '/gptSessionContent/save?sessionId=' + sessionId,
        method: 'post',
        data
    });
};

export const getSessionList = () => {
    return service<IResponseType<GptSessionVO[]>>({
        url: '/gptSession/list',
        method: 'get'
    });
};

export const createSession = (data: ChatGptRO) => {
    return service<IResponseType<string>>({
        url: '/gptSession/create',
        method: 'post',
        data
    });
};

export const delSession = (data: string) => {
    return service<IResponseType<void>>({
        url: '/gptSession/del',
        method: 'post',
        params: {
            sessionId: data
        }
    });
};

export const getContent = (data: string) => {
    return service<IResponseType<MessageContentDto[]>>({
        url: '/gptSession/contentList',
        method: 'get',
        params: {
            sessionId: data
        }
    });
};

export const getFrequency = () => {
    return service<IResponseType<number>>({
        url: '/chat/frequency',
        method: 'get'
    });
};

export const getChatConfig = () => {
    return service<IResponseType<ChatConfig>>({
        url: '/chat/chatConfig',
        method: 'get'
    });
};

export const saveChatConfig = (data: ChatConfig) => {
    return service<IResponseType<void>>({
        url: '/chat/chatConfig',
        method: 'post',
        data
    });
};

export const getProductList = () => {
    return service<IResponseType<ProductVO[]>>({
        url: '/product/list',
        method: 'get'
    });
};

export const getCode = (data: GetCodeRO) => {
    return service<IResponseType<string>>({
        url: '/free/code',
        method: 'post',
        data
    });
};

export const parseCode = (data: ParseCodeRO) => {
    return service<IResponseType<void>>({
        url: '/free/parseCode',
        method: 'post',
        data
    });
};

export const getShowWxMiniApp = () => {
    return service<IResponseType<boolean>>({
        url: '/chat/showMiniApp',
        method: 'GET'
    });
};

export const setShowWxMiniApp = (value: boolean) => {
    return service<IResponseType<void>>({
        url: '/chat/setShowMiniApp',
        method: 'POST',
        params: {
            b: value
        }
    });
};
